import { Component, OnInit } from '@angular/core';
import { RequestService } from '../services/request.service';
import { NzNotificationService,NzMessageService } from 'ng-zorro-antd';
import {
  FormBuilder,
  FormGroup,
  Validators,
  FormControl
} from '@angular/forms';
import { LocalStorageService } from '../services/local-storage.service';
import { HttpClient,HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { NzModalService } from 'ng-zorro-antd';
import { leave } from '@angular/core/src/profile/wtf_impl';
import { LoginService } from '../services/login.service';
import { ToolService } from '../services/tool.service';
@Injectable({
  providedIn: 'root'
})

@Component({
  selector: 'app-department-manager',
  templateUrl: './department-manager.component.html',
  styleUrls: ['./department-manager.component.css']
})
export class DepartmentManagerComponent implements OnInit {
  currentUser:any;
  myleaves:any;//自己的请假记录
  Unhleaves:any;//未审批请假记录
  Passleaves:any;//同意
  Unpassleaves:any;//拒绝
  absentEmploy:any;
  allleaves:any;
  Date:any;
  tabs = [ "未审批", "已被同意", "已被拒绝" ];
  types = [ "事假", "病假", "婚假", "产假", "年假"];
  percent:number;
  formatOne:any;
  validateForm: FormGroup;
  validateForm1: FormGroup;
  validateForm2: FormGroup;
  radioValue = '1';
  radioValue1 = '1';
  Hint:string;
  isVisible = false;
  isVisible1 = false;
  lid:number;
  message:string;
  startValue:Date = new Date();
  Prehandle:any;
  aLeave:any;

  submitForm(): void {
    // console.log(this.validateForm.value);
  }

  constructor(
    private http: HttpClient,
    private requestService: RequestService,
    private fb: FormBuilder,
    private fb1: FormBuilder,
    private fb2: FormBuilder,
    private stotage: LocalStorageService,
    private modalService: NzModalService,
    private loginService: LoginService,
    private nzMessageService: NzMessageService,
    private storage: LocalStorageService,
    private toolService: ToolService
  ) { }

  ngOnInit() {

    this.validateForm = this.fb.group({
      formLayout : [ '1', [Validators.required] ],
      rangePicker    : [ [] ],
      comment : [ '', [ Validators.required ] ]
    });

    this.validateForm1 = this.fb1.group({
      formLayout1 : [ '1', [Validators.required] ],
      rangePicker1    : [ [] ],
      comment1 : [ '', [ Validators.required ] ]
    });

    this.validateForm2 = this.fb2.group({
      comment2 : [ '', [ Validators.required ] ]
    });


    this.currentUser = this.stotage.getObject('currentUser');
    this.percent = this.currentUser.annualleave / 30 * 100;
    this.formatOne = percent => (Number(percent * 30 / 100).toFixed(0)) + "天";

    this.getMyLeaves();
    this.Unhandled();
    this.Passed();
    this.Unpassed();
    this.Absent();
    this.prehandled();

    //用于重置当前用户密码的表单
    this.passwordForm = this.fb.group({
      password         : [ null, [ Validators.required, Validators.minLength(6) ] ],
      checkPassword    : [ null, [ Validators.required, this.confirmationValidator, Validators.minLength(6) ] ],
    });

    if (this.storage.getObject('currentUser') != null) {
      this.currentUser = this.storage.getObject('currentUser');
      this.level = this.storage.get('level');
    };
  }

  data = [
    
  ];
  dataSet = [ ...this.data ];

  getMyLeaves() {
    this.requestService.get(`leaves/mine/${this.currentUser.eid}`, null)
      .subscribe(data => {
        this.myleaves = data;
        this.myleavesForSearch = this.myleaves;//自己的请假记录
      })
  }

  Unhandled() {
    this.requestService.get(`leaves/unhandled/${this.currentUser.eid}`, null)
      .subscribe(data => {
        this.Unhleaves = data;
        this.UnhleavesForSearch = this.Unhleaves;//未审批请假记录
      })
  }

  Passed() {
    this.requestService.get(`leaves/passed/${this.currentUser.eid}`, null)
      .subscribe(data => {
        this.Passleaves = data;
        this.PassleavesForSearch = this.Passleaves//同意
      })
  }

  Unpassed() {
    this.requestService.get(`leaves/unpassed/${this.currentUser.eid}`, null)
      .subscribe(data => {
        this.Unpassleaves = data;
        this.UnpassleavesForSearch = this.Unpassleaves//拒绝
      })
  }

  Absent() {
    this.requestService.get('leaves/absent', null)
      .subscribe(data => {
        this.absentEmploy = data;
        this.absentEmployForSearch = this.absentEmploy//缺席的员工
      })
  }

  info(): void {
    this.modalService.info({
      nzTitle: "提示",
      nzContent: this.Hint
    });
  }

  disabledEndDate = (endValue: Date): boolean => {
    endValue = new Date(endValue.getTime() - 1000 * 60 * 60 *24);
    if (!endValue || !this.startValue) {
      return false;
    }
    return endValue.getTime() <= this.startValue.getTime();
  };

  disabledEndDate1 = (endValue1: Date): boolean => {
    endValue1 = new Date(endValue1.getTime());
    if (!endValue1 || !this.startValue) {
      return false;
    }
    return endValue1.getTime() <= this.startValue.getTime();
  };

  floor(date:Date):any {
    return new Date(Number(Number(date.getTime() / (1000 * 60 * 60 * 24)).toFixed(0)) * 1000 * 60 * 60 * 24 - 1000 * 60 * 60 * 8);
  }

  Create():void {
    var between = (this.floor(new Date(this.validateForm.get("rangePicker").value[1])) - this.floor(new Date(this.validateForm.get("rangePicker").value[0]))) / (1000 * 60 * 60 *24);
    if (Number(this.validateForm.get("formLayout").value) == 5 && between > this.currentUser.annualleave) {
      this.Hint = "剩余年假不足！";
      this.info();
      return;
    }
    else if (this.floor(new Date(this.validateForm.get("rangePicker").value[0])) <= new Date() || this.floor(new Date(this.validateForm.get("rangePicker").value[0])) == undefined || this.floor(new Date(this.validateForm.get("rangePicker").value[1])) == undefined || this.floor(new Date(this.validateForm.get("rangePicker").value[0])) - this.floor(new Date(this.validateForm.get("rangePicker").value[1])) >= 0) {
      this.Hint = "日期区间错误！";
      this.info();
      return;
    }
    else if (String(this.validateForm.get("comment").value).length == 0 || this.validateForm.get("comment").value == null) {
      this.Hint = "理由不可为空！"
      this.info();
      return;
    }
    else {
      this.requestService.post('leaves/create', {employee:this.currentUser, type:Number(this.validateForm.get("formLayout").value), submit:new Date(), starttime:this.floor(new Date(this.validateForm.get("rangePicker").value[0])), endtime:this.floor(new Date(this.validateForm.get("rangePicker").value[1])), reason:this.validateForm.get("comment").value, state:0, grade:(this.currentUser.authority + 1), message:null})
      .subscribe(data => {
        this.validateForm.setValue({formLayout:'1', rangePicker:[,], comment:''});
        this.getMyLeaves();
        this.Unhandled();
        this.Hint = "提交成功！";
        this.info();
        
      },error =>{
        this.Hint = "与已有请假信息冲突！";
        this.info();
      })
    }
  }

  showModal(leave:any): void {
    this.message = leave.message;
    this.lid = leave.lid;
    this.validateForm1.setValue({formLayout1:String(leave.type), rangePicker1:[leave.starttime, leave.endtime], comment1:leave.reason});
    this.isVisible = true;
  }

  handleOk(): void {
    var between = (this.floor(new Date(this.validateForm1.get("rangePicker1").value[1])) - this.floor(new Date(this.validateForm1.get("rangePicker1").value[0]))) / (1000 * 60 * 60 *24);
    if (Number(this.validateForm1.get("formLayout1").value) == 5 && between > this.currentUser.annualleave) {
      this.Hint = "剩余年假不足！";
      this.info();
      return;
    }
    else if (this.floor(new Date(this.validateForm1.get("rangePicker1").value[0])) <= new Date() || this.floor(new Date(this.validateForm1.get("rangePicker1").value[0])) == undefined || this.floor(new Date(this.validateForm1.get("rangePicker1").value[1])) == undefined || this.floor(new Date(this.validateForm1.get("rangePicker1").value[0])) - this.floor(new Date(this.validateForm1.get("rangePicker1").value[1])) >= 0) {
      this.Hint = "日期区间错误！";
      this.info();
      return;
    }
    else if (String(this.validateForm1.get("comment1").value).length == 0 || this.validateForm1.get("comment1").value == null) {
      this.Hint = "理由不可为空！"
      this.info();
      return;
    }
    else {
      let leave = {
        employee:this.currentUser,
        type:Number(this.validateForm1.get("formLayout1").value),
        submit:new Date(),
        starttime:new Date(this.floor(new Date(this.validateForm1.get("rangePicker1").value[0]))),
        endtime:new Date(this.floor(new Date(this.validateForm1.get("rangePicker1").value[1]))),
        reason:String(this.validateForm1.get("comment1").value),
        state:0,
        grade:Number(this.currentUser.authority + 1),
        message:this.message
      }
      this.requestService.put(`leaves/update/${this.lid}`, leave)
      .subscribe(data => {
        this.getMyLeaves();
        this.Unhandled();
        this.Unpassed();
        this.Hint = "修改成功！";
        this.info();
      },error =>{
        this.Hint = "与已有请假信息冲突！";
        this.info();
      })
    }
    this.isVisible = false;
  }

  handleCancel(): void {
    this.isVisible = false;
  }

  deleteLeave(leave:any) {
    this.requestService.delete(`leaves/delete/${leave.lid}`)
      .subscribe(data => {
        this.getMyLeaves();
        this.Unhandled();
        this.Hint = "删除成功！";
        this.info();
      },error =>{
        this.Hint = "删除失败！";
        this.info();
      })
  }

  prehandled() {
    this.requestService.get(`leaves/prehandled/${this.currentUser.eid}`, null)
      .subscribe(data => {
        this.Prehandle = data;
        this.PrehandleForSerch = this.Prehandle;//待审批
      })
  }

  Pass(leave:any) {
    this.requestService.put(`leaves/pass/${leave.lid}`, null)
    .subscribe(data => {
      this.getMyLeaves();
      this.prehandled();
      this.Hint = "审批成功！";
      this.info();
    },error =>{
      this.Hint = "审批失败！";
      this.info();
    })
  }

  Unpass(leave:any) {
    this.aLeave = leave;
    this.isVisible1 = true;
  }

  handleOk1(): void {
    this.aLeave.message = this.validateForm2.get("comment2").value;
    this.requestService.put(`leaves/unpass/${this.aLeave.lid}`, this.aLeave)
    .subscribe(data => {
      this.getMyLeaves();
      this.prehandled();
      this.Hint = "审批成功！";
      this.info();
    },error =>{
      this.Hint = "审批失败！";
      this.info();
    })
    this.isVisible1 = false;
  }
  handleCancel1(): void {
    this.isVisible1 = false;
  }

  //登出
  logout() {
    this.loginService.logout();
  }

  //对于当前登录用户的管理
  isVisibleOfEditCurrentUser = false //用于当前用户信息编辑的可视
  isVisibleOfEditCurrentUserPassword = false //用于重置当前用户密码的可视
  level: string = null;
  //编辑当前用户的信息 begin
  currentUserPhone:string = null;
  showEditCurrentUserPhone(phone:string) {
    this.isVisibleOfEditCurrentUser = true;
    this.currentUserPhone = phone
  }
  handleCancelEditCurrentUser() {
    this.currentUser.phone = this.currentUserPhone;
    this.isVisibleOfEditCurrentUser = false;
  }

  handleOkEditCurrentUser() {
    this.requestService.put('employees/update', this.toolService.getRequestBody(this.currentUser))
      .subscribe(data => {
        this.nzMessageService.info('修改成功');
        //this.getEmployees();
      }, err => {
        this.nzMessageService.info('修改失败');
      })
    this.isVisibleOfEditCurrentUser = false;
  }

  passwordForm: FormGroup;
  showEditCurrentUserPassword() {
    this.isVisibleOfEditCurrentUserPassword = true;
  }

  handleCancelEditCurrentUserPassword() {
    for (const i in this.passwordForm.controls) {
      this.passwordForm.controls[ i ].markAsDirty();
      this.passwordForm.controls[ i ].updateValueAndValidity();
    }
    this.passwordForm.get('password').setValue('');
    this.passwordForm.get('checkPassword').setValue('');
    this.isVisibleOfEditCurrentUserPassword = false;
  }

  handleOkEditCurrentUserPassword() {
    for (const i in this.passwordForm.controls) {
      this.passwordForm.controls[ i ].markAsDirty();
      this.passwordForm.controls[ i ].updateValueAndValidity();
    }
    if(this.passwordForm.get('password').errors || this.passwordForm.get('checkPassword').errors) {
      this.nzMessageService.info('重置失败');
      this.passwordForm.get('password').setValue('');
      this.passwordForm.get('checkPassword').setValue('');
    } else {
      let passwd = this.currentUser.password;
      this.currentUser.password = this.passwordForm.get('password').value;
      console.log('重置密码时，查看信息: ',this.currentUser);
      this.requestService.put('employees/update', this.currentUser)
        .subscribe(data => {
          this.nzMessageService.info('重置成功');
          this.isVisibleOfEditCurrentUserPassword = false;
          this.storage.setObject('currentUser', this.currentUser);
        }, err => {
          this.nzMessageService.info('重置失败');
          this.currentUser.password = passwd;
          this.storage.setObject('currentUser', this.currentUser);
        })
      
    }
  }
  confirmationValidator = (control: FormControl): { [ s: string ]: boolean } => {
    if (!control.value) {
      return { required: true };
    } else if (control.value !== this.passwordForm.controls.password.value) {
      return { confirm: true, error: true };
    }
  }

  updateConfirmValidator(): void {
    /** wait for refresh value */
    // Promise.resolve().then(() => this.passwordForm.controls.checkPassword.updateValueAndValidity());
  }

  //对表格的操作 筛选和排序和搜索
  myleavesForSearch:any = null;//自己的请假记录
  UnhleavesForSearch:any = null;//未审批请假记录
  PassleavesForSearch:any = null;//同意
  UnpassleavesForSearch:any = null;//拒绝
  absentEmployForSearch:any = null;//缺席的员工
  PrehandleForSerch:any = null //待审批

  
  filterLeaveTypeArray = [
    { text: '事假', value: '事假'},
    { text: '病假', value: '病假'},
    { text: '婚假', value: '婚假'},
    { text: '产假', value: '产假'},
    { text: '年假', value: '年假'},
  ];
  filterLeaveStatusArrayForPast = [
    { text: '已被拒绝', value: '已被拒绝'},
    { text: '已被同意', value: '已被同意'},
  ];
  filterLeaveStatusArrayForNow = [
    { text: '已被拒绝', value: '已被拒绝'},
    { text: '已被同意', value: '已被同意'},
    { text: '未审批', value: '未审批'},
  ]

  leaveSortMap = {
    lid: null,
    name: null,
    type: null,
    starttime: null,
    endtime: null,
  }
  sortName = null;
  sortValue = null;
  
  searchLeaveType = [];
  searchLeaveStatus = [];
  //1.对于缺席
  searchValueForAbsent = '';
  filterLeaveTypeChangeForAbsent(value:[]) {
    console.log('过滤');
    this.searchLeaveType = value;
    this.searchForAbsent();
  }

  sortForAbsent(sortName: string, value: boolean): void {
    this.sortName = sortName;
    this.sortValue = value;
    for (const key in this.leaveSortMap) {
      this.leaveSortMap[ key ] = (key === sortName ? value : null);
    }
    this.searchForAbsent();
  }

  searchForAbsent(): void {
    const filterFunc = (item) => {
      console.log(this.searchLeaveType);
      let typeArray = [];
      this.searchLeaveType.forEach(el => {
        switch(el) {
          case '事假':
            typeArray.push(1);
            break;
          case '病假':
            typeArray.push(2);
            break;
          case '婚假':
            typeArray.push(3);
            break;
          case '产假':
            typeArray.push(4);
            break;
          case '年假':
            typeArray.push(5);
            break;
        }
      })
      console.log(typeArray);
      console.log((typeArray.length ? typeArray.some(type => item.type == type) : true) &&
      (item.employee.name.indexOf(this.searchValueForAbsent) !== -1));
      return (typeArray.length ? typeArray.some(type => item.type == type) : true) &&
        (item.employee.name.indexOf(this.searchValueForAbsent) !== -1);
    };
    const data = this.absentEmploy.filter(item => filterFunc(item));
    this.absentEmployForSearch = data.sort((a, b) => (this.sortValue === 'ascend') ? (a[ this.sortName ] > b[ this.sortName ] ? 1 : -1) : (b[ this.sortName ] > a[ this.sortName ] ? 1 : -1));
  }

  //2.对于我的请假单
  searchValueForMyleaves = '';
  filterLeaveTypeArrayForMyleaves(value:[]) {
    console.log('type过滤');
    this.searchLeaveType = value;
    this.searchForMyleaves();
  }

  filterLeaveStatusArrayForMyleaves(value:[]) {
    console.log('status过滤');
    this.searchLeaveStatus = value;
    this.searchForMyleaves();
  }

  sortForMyleaves(sortName: string, value: boolean): void {
    this.sortName = sortName;
    this.sortValue = value;
    for (const key in this.leaveSortMap) {
      this.leaveSortMap[ key ] = (key === sortName ? value : null);
    }
    this.searchForMyleaves();
  }

  searchForMyleaves(): void {
    const filterFunc = (item) => {
      console.log('type',this.searchLeaveType);
      let typeArray = [];
      let statusArray = [];
      this.searchLeaveType.forEach(el => {
        switch(el) {
          case '事假':
            typeArray.push(1);
            break;
          case '病假':
            typeArray.push(2);
            break;
          case '婚假':
            typeArray.push(3);
            break;
          case '产假':
            typeArray.push(4);
            break;
          case '年假':
            typeArray.push(5);
            break;
        }
      })
      console.log('status',this.searchLeaveStatus);
      this.searchLeaveStatus.forEach(el => {
        switch(el) {
          case '未审批':
            statusArray.push(0);
            break;
          case '已被同意':
            statusArray.push(1);
            break;
          case '已被拒绝':
            statusArray.push(2);
            break;
        }
      })
      console.log('statusArray:',statusArray);
      console.log(item);
      return (typeArray.length ? typeArray.some(type => item.type == type) : true) &&
        (statusArray.length ? statusArray.some(status => item.state == status) : true) &&
        (item.reason.indexOf(this.searchValueForMyleaves) !== -1);
    };
    const data = this.myleaves.filter(item => filterFunc(item));
    this.myleavesForSearch = data.sort((a, b) => (this.sortValue === 'ascend') ? (a[ this.sortName ] > b[ this.sortName ] ? 1 : -1) : (b[ this.sortName ] > a[ this.sortName ] ? 1 : -1));
  }

  //对于未审批
  searchValuesForUnhleaves = '';
  filterLeaveTypeArrayForUnhleaves(value:[]) {
    console.log('type过滤');
    this.searchLeaveType = value;
    this.searchForUnhleaves();
  }

  filterLeaveStatusArrayForUnhleaves(value:[]) {
    console.log('status过滤');
    this.searchLeaveStatus = value;
    this.searchForMyleaves();
  }

  sortForForUnhleaves(sortName: string, value: boolean): void {
    this.sortName = sortName;
    this.sortValue = value;
    for (const key in this.leaveSortMap) {
      this.leaveSortMap[ key ] = (key === sortName ? value : null);
    }
    this.searchForUnhleaves();
  }

  searchForUnhleaves(): void {
    const filterFunc = (item) => {
      console.log('type',this.searchLeaveType);
      let typeArray = [];
      let statusArray = [];
      this.searchLeaveType.forEach(el => {
        switch(el) {
          case '事假':
            typeArray.push(1);
            break;
          case '病假':
            typeArray.push(2);
            break;
          case '婚假':
            typeArray.push(3);
            break;
          case '产假':
            typeArray.push(4);
            break;
          case '年假':
            typeArray.push(5);
            break;
        }
      })
      console.log('status',this.searchLeaveStatus);
      this.searchLeaveStatus.forEach(el => {
        switch(el) {
          case '未审批':
            statusArray.push(0);
            break;
          case '已被同意':
            statusArray.push(1);
            break;
          case '已被拒绝':
            statusArray.push(2);
            break;
        }
      })
      console.log('statusArray:',statusArray);
      console.log('type', typeArray);
      console.log(item);
      console.log('type是否存在: ',(typeArray.length ? typeArray.some(type => item.type == type) : true));
      console.log('status是否存在', (statusArray.length ? statusArray.some(status => item.state == status) : true) );
      console.log('reason是否存在', (item.reason.indexOf(this.UnhleavesForSearch) !== -1));

      return (typeArray.length ? typeArray.some(type => item.type == type) : true) &&
        (statusArray.length ? statusArray.some(status => item.state == status) : true) &&
        (item.reason.indexOf(this.searchValuesForUnhleaves) !== -1);
    };
    const data = this.Unhleaves.filter(item => filterFunc(item));
    this.UnhleavesForSearch = data.sort((a, b) => (this.sortValue === 'ascend') ? (a[ this.sortName ] > b[ this.sortName ] ? 1 : -1) : (b[ this.sortName ] > a[ this.sortName ] ? 1 : -1));
  }

   //对于已被拒绝
   searchValuesForUnpassleaves = '';
   filterLeaveTypeArrayForUnpassleaves(value:[]) {
     console.log('type过滤');
     this.searchLeaveType = value;
     this.searchForUnpassleaves();
   }
 
   filterLeaveStatusArrayForUnpassleaves(value:[]) {
     console.log('status过滤');
     this.searchLeaveStatus = value;
     this.searchForUnpassleaves();
   }
 
   sortForForUnpassleaves(sortName: string, value: boolean): void {
     this.sortName = sortName;
     this.sortValue = value;
     for (const key in this.leaveSortMap) {
       this.leaveSortMap[ key ] = (key === sortName ? value : null);
     }
     this.searchForUnpassleaves();
   }
 
   searchForUnpassleaves(): void {
     const filterFunc = (item) => {
       console.log('type',this.searchLeaveType);
       let typeArray = [];
       let statusArray = [];
       this.searchLeaveType.forEach(el => {
         switch(el) {
           case '事假':
             typeArray.push(1);
             break;
           case '病假':
             typeArray.push(2);
             break;
           case '婚假':
             typeArray.push(3);
             break;
           case '产假':
             typeArray.push(4);
             break;
           case '年假':
             typeArray.push(5);
             break;
         }
       })
       console.log('status',this.searchLeaveStatus);
       this.searchLeaveStatus.forEach(el => {
         switch(el) {
           case '未审批':
             statusArray.push(0);
             break;
           case '已被同意':
             statusArray.push(1);
             break;
           case '已被拒绝':
             statusArray.push(2);
             break;
         }
       })
       console.log('statusArray:',statusArray);
       console.log('type', typeArray);
       console.log(item);
       console.log('type是否存在: ',(typeArray.length ? typeArray.some(type => item.type == type) : true));
       console.log('status是否存在', (statusArray.length ? statusArray.some(status => item.state == status) : true) );
       console.log('reason是否存在', (item.reason.indexOf(this.UnhleavesForSearch) !== -1));
 
       return (typeArray.length ? typeArray.some(type => item.type == type) : true) &&
         (statusArray.length ? statusArray.some(status => item.state == status) : true) &&
         (item.reason.indexOf(this.searchValuesForUnpassleaves) !== -1);
     };
     const data = this.Unpassleaves.filter(item => filterFunc(item));
     this.UnpassleavesForSearch = data.sort((a, b) => (this.sortValue === 'ascend') ? (a[ this.sortName ] > b[ this.sortName ] ? 1 : -1) : (b[ this.sortName ] > a[ this.sortName ] ? 1 : -1));
   }


   //对于审批请假单
   searchValueOfSSNForPrehandle = '';
   searchValueOfNameForPrehandle = '';
   filterLeaveTypeArrayForPrehandle(value:[]) {
    console.log('type过滤');
    this.searchLeaveType = value;
    this.searchForPrehandle();
  }

  filterLeaveStatusArrayForPrehandle(value:[]) {
    console.log('status过滤');
    this.searchLeaveStatus = value;
    this.searchForUnpassleaves();
  }

  sortForForPrehandle(sortName: string, value: boolean): void {
    this.sortName = sortName;
    this.sortValue = value;
    for (const key in this.leaveSortMap) {
      this.leaveSortMap[ key ] = (key === sortName ? value : null);
    }
    this.searchForPrehandle();
  }

  searchForPrehandle(): void {
    const filterFunc = (item) => {
      console.log('type',this.searchLeaveType);
      let typeArray = [];
      let statusArray = [];
      this.searchLeaveType.forEach(el => {
        switch(el) {
          case '事假':
            typeArray.push(1);
            break;
          case '病假':
            typeArray.push(2);
            break;
          case '婚假':
            typeArray.push(3);
            break;
          case '产假':
            typeArray.push(4);
            break;
          case '年假':
            typeArray.push(5);
            break;
        }
      })
      console.log('status',this.searchLeaveStatus);
      this.searchLeaveStatus.forEach(el => {
        switch(el) {
          case '未审批':
            statusArray.push(0);
            break;
          case '已被同意':
            statusArray.push(1);
            break;
          case '已被拒绝':
            statusArray.push(2);
            break;
        }
      })
      console.log('statusArray:',statusArray);
      console.log('type', typeArray);
      console.log(item);
      console.log('type是否存在: ',(typeArray.length ? typeArray.some(type => item.type == type) : true));
      console.log('status是否存在', (statusArray.length ? statusArray.some(status => item.state == status) : true) );
      console.log('reason是否存在', (item.reason.indexOf(this.UnhleavesForSearch) !== -1));

      return (typeArray.length ? typeArray.some(type => item.type == type) : true) &&
        (statusArray.length ? statusArray.some(status => item.state == status) : true) &&
        (item.employee.name.indexOf(this.searchValueOfNameForPrehandle) !== -1) &&
        (item.employee.eid.indexOf(this.searchValueOfSSNForPrehandle) !== -1);
    };
    const data = this.Prehandle.filter(item => filterFunc(item));
    this.PrehandleForSerch = data.sort((a, b) => (this.sortValue === 'ascend') ? (a[ this.sortName ] > b[ this.sortName ] ? 1 : -1) : (b[ this.sortName ] > a[ this.sortName ] ? 1 : -1));
  }

  cancel(){}
}

